home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / mint / netlib / include / file.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-27  |  15.3 KB  |  492 lines

  1. /*
  2.  *    This file defines various structures and constants used by
  3.  *    MiNT kernel, device drivers and filesystems.
  4.  *    It does only work with ANSI compilers and prototypes.
  5.  *
  6.  *    file.h is derived from filesys.h, which is
  7.  *
  8.  *     Copyright 1991,1992 Eric R. Smith. This file may be re-distributed
  9.  *     as long as this notice remains intact.
  10.  */
  11.  
  12. #ifndef _FILE_H
  13. #define _FILE_H
  14.  
  15. #define NAME_MAX 32
  16. #define PATH_MAX 128
  17.  
  18. struct filesys;        /* forward declaration */
  19. struct devdrv;        /* ditto */
  20.  
  21. /* structure for timeouts, the `void*'s are really `struct proc *'s */
  22. typedef struct timeout {
  23.     struct timeout    *next;
  24.     void    *proc;
  25.     long    when;
  26.     void    (*func) (void *); /* function to call at timeout */
  27.     short    flags;
  28. } TIMEOUT;
  29.  
  30. typedef struct f_cookie {
  31.     struct filesys *fs;    /* filesystem that knows about this cookie */
  32.     unsigned short    dev;    /* device info (e.g. Rwabs device number) */
  33.     unsigned short    aux;    /* extra data that the file system may want */
  34.     long    index;        /* this+dev uniquely identifies a file */
  35. } fcookie;
  36.  
  37. /* structure for opendir/readdir/closedir */
  38. typedef struct dirstruct {
  39.     fcookie fc;        /* cookie for this directory */
  40.     unsigned short    index;    /* index of the current entry */
  41.     unsigned short    flags;    /* flags (e.g. tos or not) */
  42. #define TOS_SEARCH    0x01
  43.     char    fsstuff[60];    /* anything else the file system wants */
  44.                 /* NOTE: this must be at least 45 bytes */
  45. } DIR;
  46.  
  47. /* structure for getxattr */
  48. typedef struct xattr {
  49.     unsigned short    mode;
  50. /* file types */
  51. #define S_IFMT    0170000        /* mask to select file type */
  52. #define S_IFCHR    0020000        /* BIOS special file */
  53. #define S_IFDIR    0040000        /* directory file */
  54. #define S_IFREG 0100000        /* regular file */
  55. #define S_IFIFO 0120000        /* FIFO */
  56. #define S_IMEM    0140000        /* memory region or process */
  57. #define S_IFLNK    0160000        /* symbolic link */
  58.  
  59. /* special bits: setuid, setgid, sticky bit */
  60. #define S_ISUID    04000
  61. #define S_ISGID 02000
  62. #define S_ISVTX    01000
  63.  
  64. /* file access modes for user, group, and other*/
  65. #define S_IRUSR    0400
  66. #define S_IWUSR 0200
  67. #define S_IXUSR 0100
  68. #define S_IRGRP 0040
  69. #define S_IWGRP    0020
  70. #define S_IXGRP    0010
  71. #define S_IROTH    0004
  72. #define S_IWOTH    0002
  73. #define S_IXOTH    0001
  74. #define DEFAULT_DIRMODE (0777)
  75. #define DEFAULT_MODE    (0666)
  76.     long    index;
  77.     unsigned short    dev;
  78.     unsigned short    reserved1;
  79.     unsigned short    nlink;
  80.     unsigned short    uid;
  81.     unsigned short    gid;
  82.     long    size;
  83.     long    blksize, nblocks;
  84.     short    mtime, mdate;
  85.     short    atime, adate;
  86.     short    ctime, cdate;
  87.     short    attr;
  88.     short    reserved2;
  89.     long    reserved3[2];
  90. } XATTR;
  91.  
  92. typedef struct fileptr {
  93.     short    links;        /* number of copies of this descriptor */
  94.     unsigned short    flags;        /* file open mode and other file flags */
  95.     long    pos;        /* position in file */
  96.     long    devinfo;    /* device driver specific info */
  97.     fcookie    fc;        /* file system cookie for this file */
  98.     struct devdrv *dev; /* device driver that knows how to deal with this */
  99.     struct fileptr *next; /* link to next fileptr for this file */
  100. } FILEPTR;
  101.  
  102. /* lock structure */
  103. struct flock {
  104.     short l_type;            /* type of lock */
  105. #define F_RDLCK        O_RDONLY
  106. #define F_WRLCK        O_WRONLY
  107. #define F_UNLCK        3
  108.     short l_whence;            /* SEEK_SET, SEEK_CUR, SEEK_END */
  109.     long l_start;            /* start of locked region */
  110.     long l_len;            /* length of locked region */
  111.     short l_pid;            /* pid of locking process
  112.                         (F_GETLK only) */
  113. };
  114.  
  115. /* LOCK structure used by the kernel internally */
  116. typedef struct ilock {
  117.     struct flock l;
  118.     struct ilock *next;
  119.     long  reserved[4];
  120. } LOCK;
  121.  
  122. typedef struct devdrv {
  123.     long (*open)    (FILEPTR *f);
  124.     long (*write)    (FILEPTR *f, char *buf, long bytes);
  125.     long (*read)    (FILEPTR *f, char *buf, long bytes);
  126.     long (*lseek)    (FILEPTR *f, long where, short whence);
  127.     long (*ioctl)    (FILEPTR *f, short mode, void *buf);
  128.     long (*datime)    (FILEPTR *f, short *timeptr, short rwflag);
  129.     long (*close)    (FILEPTR *f, short pid);
  130.     long (*select)    (FILEPTR *f, long proc, short mode);
  131.     void (*unselect) (FILEPTR *f, long proc, short mode);
  132.     long    reserved[3];    /* reserved for future use */
  133. } DEVDRV;
  134.  
  135. typedef struct filesys {
  136.     struct    filesys    *next;    /* link to next file system on chain */
  137.     long    fsflags;
  138. #define FS_KNOPARSE    0x01    /* kernel shouldn't do parsing */
  139. #define FS_CASESENSITIVE    0x02    /* file names are case sensitive */
  140. #define FS_NOXBIT    0x04    /* if a file can be read, it can be executed */
  141. #define    FS_LONGPATH    0x08    /* file system understands "size" argument to
  142.                    "getname" */
  143.  
  144.     long    (*root) (short drv, fcookie *fc);
  145.     long    (*lookup) (fcookie *dir, char *name, fcookie *fc);
  146.     long    (*creat) (fcookie *dir, char *name, unsigned short mode,
  147.                 short attrib, fcookie *fc);
  148.     DEVDRV *(*getdev) (fcookie *fc, long *devspecial);
  149.     long    (*getxattr) (fcookie *fc, XATTR *xattr);
  150.     long    (*chattr) (fcookie *fc, short attr);
  151.     long    (*chown) (fcookie *fc, short uid, short gid);
  152.     long    (*chmode) (fcookie *fc, unsigned short mode);
  153.     long    (*mkdir) (fcookie *dir, char *name, unsigned short mode);
  154.     long    (*rmdir) (fcookie *dir, char *name);
  155.     long    (*remove) (fcookie *dir, char *name);
  156.     long    (*getname) (fcookie *relto, fcookie *dir, char *pathname,
  157.                 short size);
  158.     long    (*rename) (fcookie *olddir, char *oldname,
  159.                 fcookie *newdir, char *newname);
  160.     long    (*opendir) (DIR *dirh, short tosflag);
  161.     long    (*readdir) (DIR *dirh, char *nm, short nmlen, fcookie *fc);
  162.     long    (*rewinddir) (DIR *dirh);
  163.     long    (*closedir) (DIR *dirh);
  164.     long    (*pathconf) (fcookie *dir, short which);
  165.     long    (*dfree) (fcookie *dir, long *buf);
  166.     long    (*writelabel) (fcookie *dir, char *name);
  167.     long    (*readlabel) (fcookie *dir, char *name, short namelen);
  168.     long    (*symlink) (fcookie *dir, char *name, char *to);
  169.     long    (*readlink) (fcookie *dir, char *buf, short len);
  170.     long    (*hardlink) (fcookie *fromdir, char *fromname,
  171.                 fcookie *todir, char *toname);
  172.     long    (*fscntl) (fcookie *dir, char *name, short cmd, long arg);
  173.     long    (*dskchng) (short drv);
  174.     long    (*release) (fcookie *fc);
  175.     long    (*dupcookie) (fcookie *dest, fcookie *src);
  176.  
  177. } FILESYS;
  178.  
  179. /*
  180.  * this is the structure passed to loaded file systems to tell them
  181.  * about the kernel
  182.  */
  183.  
  184. typedef long (*_LongFunc)();
  185.  
  186. struct kerinfo {
  187.     short    maj_version;    /* kernel version number */
  188.     short    min_version;    /* minor kernel version number */
  189.     unsigned short default_mode;    /* default file access mode */
  190.     short    reserved1;    /* room for expansion */
  191.  
  192. /* OS functions */
  193.     _LongFunc *bios_tab;     /* pointer to the BIOS entry points */
  194.     _LongFunc *dos_tab;    /* pointer to the GEMDOS entry points */
  195.  
  196. /* media change vector */
  197.     void    (*drvchng) (short);
  198.  
  199. /* Debugging stuff */
  200.     void    (*trace) (char *, ...);
  201.     void    (*debug) (char *, ...);
  202.     void    (*alert) (char *, ...);
  203.     void    (*fatal) (char *, ...);
  204.  
  205. /* memory allocation functions */
  206.     void *    (*kmalloc) (long);
  207.     void    (*kfree) (void *);
  208.     void *    (*umalloc) (long);
  209.     void    (*ufree) (void *);
  210.  
  211. /* utility functions for string manipulation */
  212.     short    (*strnicmp) (char *, char *, short);
  213.     short    (*stricmp) (char *, char *);
  214.     char *    (*strlwr) (char *);
  215.     char *    (*strupr) (char *);
  216.     short    (*sprintf) (char *, char *, ...);
  217.  
  218. /* utility functions for manipulating time */
  219.     void    (*millis_time) (unsigned long, short *);
  220.     long    (*unixtim) (unsigned short, unsigned short);
  221.     long    (*dostim) (long);
  222.  
  223. /* utility functions for dealing with pauses */
  224.     void    (*nap) (unsigned short);
  225.     short    (*sleep) (short que, long cond);
  226.     void    (*wake) (short que, long cond);
  227.     void    (*wakeselect) (long param);
  228.  
  229. /* file system utility functions */
  230.     short    (*denyshare) (FILEPTR *, FILEPTR *);
  231.     LOCK *    (*denylock) (LOCK *, LOCK *);
  232.  
  233. /* functions for adding/cancelling timeouts */
  234.     TIMEOUT * (*addtimeout) (long, void (*)());
  235.     void    (*canceltimeout) (TIMEOUT *);
  236.     TIMEOUT * (*addroottimeout) (long, void (*)(), short);
  237.     void    (*cancelroottimeout) (TIMEOUT *);
  238.     long    (*ikill) (short, short);
  239.     void    (*iwake) (short, long, short);
  240.  
  241. /* reserved for future use */
  242.     long    res2[3];
  243. };
  244.  
  245. /* flags for open() modes */
  246. #define O_RWMODE      0x03    /* isolates file read/write mode */
  247. #    define O_RDONLY    0x00
  248. #    define O_WRONLY    0x01
  249. #    define O_RDWR    0x02
  250. #    define O_EXEC    0x03    /* execute file; used by kernel only */
  251.  
  252. #define O_APPEND    0x08    /* all writes go to end of file */
  253.  
  254. #define O_SHMODE    0x70    /* isolates file sharing mode */
  255. #    define O_COMPAT    0x00    /* compatibility mode */
  256. #    define O_DENYRW    0x10    /* deny both read and write access */
  257. #    define O_DENYW    0x20    /* deny write access to others */
  258. #    define O_DENYR    0x30    /* deny read access to others */
  259. #    define O_DENYNONE 0x40    /* don't deny any access to others */
  260.  
  261. #define O_NOINHERIT    0x80    /* children don't get this file descriptor */
  262.  
  263. #define O_NDELAY    0x100    /* don't block for i/o on this file */
  264. #define O_CREAT        0x200    /* create file if it doesn't exist */
  265. #define O_TRUNC        0x400    /* truncate file to 0 bytes if it does exist */
  266. #define O_EXCL        0x800    /* fail open if file exists */
  267.  
  268. #define O_USER        0x0fff    /* isolates user-settable flag bits */
  269.  
  270. #define O_GLOBAL    0x1000    /* for Fopen: opens a global file handle */
  271.  
  272. /* kernel mode bits -- the user can't set these! */
  273. #define O_TTY        0x2000    /* FILEPTR refers to a terminal */
  274. #define O_HEAD        0x4000    /* FILEPTR is the master side of a fifo */
  275. #define O_LOCK        0x8000    /* FILEPTR has had locking Fcntl's performed */
  276.  
  277.  
  278. /* GEMDOS file attributes */
  279.  
  280. /* macros to be applied to FILEPTRS to determine their type */
  281. #define is_terminal(f) (f->flags & O_TTY)
  282.  
  283. /* lseek() origins */
  284. #define    SEEK_SET    0        /* from beginning of file */
  285. #define    SEEK_CUR    1        /* from current location */
  286. #define    SEEK_END    2        /* from end of file */
  287.  
  288. /* The requests for Dpathconf() */
  289. #define DP_IOPEN    0    /* internal limit on # of open files */
  290. #define DP_MAXLINKS    1    /* max number of hard links to a file */
  291. #define DP_PATHMAX    2    /* max path name length */
  292. #define DP_NAMEMAX    3    /* max length of an individual file name */
  293. #define DP_ATOMIC    4    /* # of bytes that can be written atomically */
  294. #define DP_TRUNC    5    /* file name truncation behavior */
  295. #    define    DP_NOTRUNC    0    /* long filenames give an error */
  296. #    define    DP_AUTOTRUNC    1    /* long filenames truncated */
  297. #    define    DP_DOSTRUNC    2    /* DOS truncation rules in effect */
  298. #define DP_CASE        6    /* file name case conversion behavior */
  299. #    define    DP_CASESENS    0    /* case sensitive */
  300. #    define    DP_CASECONV    1    /* case always converted */
  301. #    define    DP_CASEINSENS    2    /* case insensitive, preserved */
  302.  
  303. #define DP_MAXREQ    6    /* highest legal request */
  304.  
  305. /* Dpathconf and Sysconf return this when a value is not limited
  306.    (or is limited only by available memory) */
  307.  
  308. #define UNLIMITED    0x7fffffffL
  309.  
  310. /* various character constants and defines for TTY's */
  311. #define MiNTEOF 0x0000ff1a    /* 1a == ^Z */
  312.  
  313. /* defines for tty_read */
  314. #define RAW    0
  315. #define COOKED    0x1
  316. #define NOECHO    0
  317. #define ECHO    0x2
  318. #define ESCSEQ    0x04        /* cursor keys, etc. get escape sequences */
  319.  
  320. /* constants for various Fcntl commands */
  321. /* constants for Fcntl calls */
  322. #define F_DUPFD        0        /* handled by kernel */
  323. #define F_GETFD        1        /* handled by kernel */
  324. #define F_SETFD        2        /* handled by kernel */
  325. #    define FD_CLOEXEC    1    /* close on exec flag */
  326.  
  327. #define F_GETFL        3        /* handled by kernel */
  328. #define F_SETFL        4        /* handled by kernel */
  329. #define F_GETLK        5
  330. #define F_SETLK        6
  331. #define F_SETLKW    7
  332.  
  333. /* more constants for various Fcntl's */
  334. #define FSTAT        (('F'<< 8) | 0)        /* handled by kernel */
  335. #define FIONREAD    (('F'<< 8) | 1)
  336. #define FIONWRITE    (('F'<< 8) | 2)
  337. #define FIOEXCEPT    (('F'<< 8) | 5)
  338. #define TIOCGETP    (('T'<< 8) | 0)
  339. #define TIOCSETN    (('T'<< 8) | 1)
  340. #define TIOCGETC    (('T'<< 8) | 2)
  341. #define TIOCSETC    (('T'<< 8) | 3)
  342. #define TIOCGLTC    (('T'<< 8) | 4)
  343. #define TIOCSLTC    (('T'<< 8) | 5)
  344. #define TIOCGPGRP    (('T'<< 8) | 6)
  345. #define TIOCSPGRP    (('T'<< 8) | 7)
  346. #define TIOCFLUSH    (('T'<< 8) | 8)
  347. #define TIOCSTOP    (('T'<< 8) | 9)
  348. #define TIOCSTART    (('T'<< 8) | 10)
  349. #define TIOCGWINSZ    (('T'<< 8) | 11)
  350. #define TIOCSWINSZ    (('T'<< 8) | 12)
  351. #define TIOCGXKEY    (('T'<< 8) | 13)
  352. #define TIOCSXKEY    (('T'<< 8) | 14)
  353. #define TIOCIBAUD    (('T'<< 8) | 18)
  354. #define TIOCOBAUD    (('T'<< 8) | 19)
  355. #define TIOCCBRK    (('T'<< 8) | 20)
  356. #define TIOCSBRK    (('T'<< 8) | 21)
  357. #define TIOCGFLAGS    (('T'<< 8) | 22)
  358. #define TIOCSFLAGS    (('T'<< 8) | 23)
  359. #define TIOCOUTQ    (('T'<< 8) | 24)
  360. #define TIOCSETP    (('T'<< 8) | 25)
  361. #define TIOCHPCL    (('T'<< 8) | 26)
  362. #define TIOCCAR        (('T'<< 8) | 27)
  363. #define TIOCNCAR    (('T'<< 8) | 28)
  364. #define TIOCWONLINE    (('T'<< 8) | 29)
  365. #define TIOCSFLAGSB    (('T'<< 8) | 30)
  366. #define TIOCGSTATE    (('T'<< 8) | 31)
  367. #define TIOCSSTATEB    (('T'<< 8) | 32)
  368. #define TIOCGVMIN    (('T'<< 8) | 33)
  369. #define TIOCSVMIN    (('T'<< 8) | 34)
  370.  
  371. #define TCURSOFF    (('c'<< 8) | 0)
  372. #define TCURSON        (('c'<< 8) | 1)
  373. #define TCURSBLINK    (('c'<< 8) | 2)
  374. #define TCURSSTEADY    (('c'<< 8) | 3)
  375. #define TCURSSRATE    (('c'<< 8) | 4)
  376. #define TCURSGRATE    (('c'<< 8) | 5)
  377.  
  378. #define PPROCADDR    (('P'<< 8) | 1)
  379. #define PBASEADDR    (('P'<< 8) | 2)
  380. #define PCTXTSIZE    (('P'<< 8) | 3)
  381. #define PSETFLAGS    (('P'<< 8) | 4)
  382. #define PGETFLAGS    (('P'<< 8) | 5)
  383. #define PTRACESFLAGS    (('P'<< 8) | 6)
  384. #define PTRACEGFLAGS    (('P'<< 8) | 7)
  385. #    define    P_ENABLE    (1 << 0)    /* enable tracing */
  386.  
  387. #define PTRACEGO    (('P'<< 8) | 8)
  388. #define PTRACEFLOW    (('P'<< 8) | 9)
  389. #define PTRACESTEP    (('P'<< 8) | 10)
  390. #define PTRACE11    (('P'<< 8) | 11)    /* unused, reserved */
  391.  
  392. #define SHMGETBLK    (('M'<< 8) | 0)
  393. #define SHMSETBLK    (('M'<< 8) | 1)
  394.  
  395. /* terminal control constants (tty.sg_flags) */
  396. #define T_CRMOD        0x0001
  397. #define T_CBREAK    0x0002
  398. #define T_ECHO        0x0004
  399. #define T_RAW        0x0010
  400. #define T_TOS        0x0080
  401. #define T_TOSTOP    0x0100
  402. #define T_XKEY        0x0200        /* Fread returns escape sequences for
  403.                        cursor keys, etc. */
  404.  
  405. /* the following are terminal status flags (tty.state) */
  406. /* (the low byte of tty.state indicates a part of an escape sequence still
  407.  * hasn't been read by Fread, and is an index into that escape sequence)
  408.  */
  409. #define TS_ESC        0x00ff
  410. #define TS_HOLD        0x1000        /* hold (e.g. ^S/^Q) */
  411. #define TS_COOKED    0x8000        /* interpret control chars */
  412.  
  413. /* structures for terminals */
  414. struct tchars {
  415.     char t_intrc;
  416.     char t_quitc;
  417.     char t_startc;
  418.     char t_stopc;
  419.     char t_eofc;
  420.     char t_brkc;
  421. };
  422.  
  423. struct ltchars {
  424.     char t_suspc;
  425.     char t_dsuspc;
  426.     char t_rprntc;
  427.     char t_flushc;
  428.     char t_werasc;
  429.     char t_lnextc;
  430. };
  431.  
  432. struct sgttyb {
  433.     char sg_ispeed;
  434.     char sg_ospeed;
  435.     char sg_erase;
  436.     char sg_kill;
  437.     unsigned short sg_flags;
  438. };
  439.  
  440. struct winsize {
  441.     short    ws_row;
  442.     short    ws_col;
  443.     short    ws_xpixel;
  444.     short    ws_ypixel;
  445. };
  446.  
  447. struct xkey {
  448.     short    xk_num;
  449.     char    xk_def[8];
  450. };
  451.  
  452. struct tty {
  453.     short        pgrp;        /* process group of terminal */
  454.     short        state;        /* terminal status, e.g. stopped */
  455.     short        use_cnt;    /* number of times terminal is open */
  456.     short        res1;        /* reserved for future expansion */
  457.     struct sgttyb     sg;
  458.     struct tchars     tc;
  459.     struct ltchars     ltc;
  460.     struct winsize    wsiz;
  461.     long        rsel;        /* selecting process for read */
  462.     long        wsel;        /* selecting process for write */
  463.     char        *xkey;        /* extended keyboard table */
  464.     long        rsrvd[3];    /* reserved for future expansion */
  465. };
  466.  
  467. /* defines and declarations for Dcntl operations */
  468.  
  469. #define DEV_INSTALL    0xde02
  470. #define DEV_NEWBIOS    0xde01
  471. #define DEV_NEWTTY    0xde00
  472.  
  473. struct dev_descr {
  474.     DEVDRV    *driver;
  475.     short    dinfo;
  476.     short    flags;
  477.     struct tty *tty;
  478.     long    reserved[4];
  479. };
  480.  
  481. /* defines for TOS attribute bytes */
  482. #ifndef FA_RDONLY
  483. #define           FA_RDONLY           0x01
  484. #define           FA_HIDDEN           0x02
  485. #define           FA_SYSTEM           0x04
  486. #define           FA_LABEL               0x08
  487. #define           FA_DIR               0x10
  488. #define           FA_CHANGED           0x20
  489. #endif
  490.  
  491. #endif /* _FILE_H */
  492.